package com.itheima;

/**
 * 2025/4/12 9:25
 * 电影信息展示系统
 */
public class MovieOperation {

    // 电影数组，用于存储电影信息数据
    private Movie[] movies;

    //添加带参的构造函数
    public MovieOperation(Movie[] movies) {
        this.movies = movies;
    }

    //打印movies数组
    public void printInfo(){
        //遍历数组
//        for (int i = 0; i < movies.length; i++) {
//            Movie movie = movies[i];
//            System.out.println("id="+movie.getId()+",name="+movie.getName()+",price="+movie.getPrice());
//        }

        for (Movie movie : movies) {
            System.out.println("id=" + movie.getId() + ",name=" + movie.getName() + ",price=" + movie.getPrice());
        }
    }
    //根据id查询电影信息
    public void findById(int id){
        for (Movie movie : movies) {
            if(movie.getId() == id){
                System.out.println("id=" + movie.getId() + ",name=" + movie.getName() + ",price=" + movie.getPrice());
                //代表方法的结束
                return;
            }
        }
        System.out.println("没有找到id为"+id+"的电影");
    }
}
